package com.losdun.cms.controller.app;

import com.losdun.cms.domain.Cases;
import com.losdun.cms.domain.CmsCategory;
import com.losdun.cms.domain.News;
import com.losdun.cms.service.ICasesService;
import com.losdun.cms.service.ICmsCategoryService;
import com.losdun.cms.service.INewsService;
import com.losdun.cms.service.IVideoService;
import com.losdun.common.annotation.Anonymous;
import com.losdun.common.core.controller.BaseController;
import com.losdun.common.core.domain.AjaxResult;
import com.losdun.common.core.page.TableDataInfo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @Description
 * @Author Sword.Ye
 * @Date 2025/8/19
 **/
@Slf4j
@RestController
@RequestMapping("/app/cms")
public class AppCmsController extends BaseController {

    @Autowired
    private ICmsCategoryService cmsCategoryService;
    @Autowired
    private INewsService newsService;
    @Autowired
    private ICasesService casesService;
    @Autowired
    private IVideoService videoService;

    @Anonymous
    @GetMapping("/category/list")
    public AjaxResult categoryList(CmsCategory cmsCategory)
    {
        List<CmsCategory> list = cmsCategoryService.selectCmsCategoryList(cmsCategory);
        return success(list);
    }

    @Anonymous
    @GetMapping("/news/list")
    public TableDataInfo newsList(News news)
    {
        startPage();
        List<News> list = newsService.selectNewsList(news);
        return getDataTable(list);
    }

    @Anonymous
    @GetMapping(value = "/news/detail/{id}")
    public AjaxResult newsDetail(@PathVariable("id") Long id)
    {

        return success(newsService.selectNewsById(id));
    }

    @Anonymous
    @GetMapping("/cases/list")
    public TableDataInfo casesList(Cases cases)
    {
        startPage();
        List<Cases> list = casesService.selectCasesList(cases);
        return getDataTable(list);
    }

    @Anonymous
    @GetMapping(value = "/cases/detail/{id}")
    public AjaxResult casesDetail(@PathVariable("id") Long id)
    {
        return success(casesService.selectCasesById(id));
    }

    @Anonymous
    @GetMapping(value = "/video/detail/{id}")
    public AjaxResult videoDetail(@PathVariable("id") Long id)
    {
        return success(videoService.selectVideoById(id));
    }
}
